<style>
    .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
</style>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <form class="layui-form layuimini-form" action="" lay-filter="edit-form" id="edit-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">账号</label>
                <div class="layui-input-block">
                    <input type="text" name="username" value="admin" class="layui-input" readonly disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">昵称</label>
                <div class="layui-input-block">
                    <input type="text" name="nickname" placeholder="请输入昵称" class="layui-input" autocomplete="off">
                    <tip>自定义昵称，不超过32个字符。</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-block">
                    <input type="number" name="phone" lay-reqtext="请输入正确的手机号" lay-verify="phone" placeholder="请输入手机号" class="layui-input" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电子邮箱</label>
                <div class="layui-input-block">
                    <input type="email" name="email" lay-reqtext="请输入正确的电子邮箱" lay-verify="email" placeholder="请输入电子邮箱" class="layui-input" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form','miniPage', 'miniAjax'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniAjax= layui.miniAjax,
            miniPage = layui.miniPage;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();


        miniAjax.get({
            url: '/auth/getUserInfo',
            success: function (res) {
                if (res.code == '0') {
                    // layer.msg(res.msg, {time: 1000, icon: 1});
                    form.val('edit-form', res.data);
                } else {
                    layer.msg(res.msg, {time: 1000, icon: 2});
                }
            }
        });


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            layer.confirm('确定要修改个人信息吗', {
                title: '提示'
            }, function (index) {
                miniAjax.postJSON({
                    url: '/auth/setting',
                    data: JSON.stringify(data.field),
                    success: function (res) {
                        if (res.code == '0') {
                            layer.msg(res.msg, {time: 1000, icon: 1}, function () {
                                layer.close(index);
                                miniPage.hashHome();
                            });
                        } else {
                            layer.msg(res.msg, {time: 1000, icon: 2});
                        }
                    }
                });
            });

            return false;
        });

    });
</script>